package com.moss.cloud.common.flow.operation.factory;

import com.moss.cloud.common.flow.enums.TaskState;
import com.moss.cloud.common.flow.operation.StateOperation;
import com.moss.cloud.common.flow.operation.impl.InProgressState;
import com.moss.cloud.common.flow.operation.impl.NotStartedState;
import com.moss.cloud.common.flow.operation.impl.PassState;
import com.moss.cloud.common.flow.operation.impl.RefuseState;
import lombok.experimental.UtilityClass;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@UtilityClass
public class StateFactory {
    static Map<Integer, StateOperation> operationMap = new HashMap<>();

    static {
        // 未开始
        operationMap.put(TaskState.NO_START.getType(), new NotStartedState());
        // 进行中
        operationMap.put(TaskState.IN_PROGRESS.getType(), new InProgressState());
        // 通过
        operationMap.put(TaskState.PASS.getType(), new PassState());
        // 拒绝
        operationMap.put(TaskState.REFUSE.getType(), new RefuseState());
    }

    public static Optional<StateOperation> stateType(Integer type) {
        return Optional.ofNullable(operationMap.get(type));
    }
}
